<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:mo="https://gitee.com/aun/Timo"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:replace="/common/template :: header(~{::title},~{::link},~{::style})">
</head>
<body class="timo-layout-page">

<div class="layui-card">
    <div class="layui-card-body">
        <div class="timo-table-wrap">
            <table class="layui-table timo-table">
                <thead>
                <tr>
                    <th class="timo-table-checkbox">
                        <label class="timo-checkbox"><input type="checkbox">
                            <i class="layui-icon layui-icon-ok"></i></label>
                    </th>
                    <th class="sortable" data-field="username">账号</th>
                    <th class="sortable" data-field="nickname">姓名</th>
<!--                    <th class="sortable" data-field="dept">所在部门</th>-->
                    <th class="sortable" data-field="sex">性别</th>
                    <th class="sortable" data-field="phone">电话</th>
                    <th class="sortable" data-field="email">邮箱</th>
                    <th class="sortable" data-field="createDate">创建时间</th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="item:${list}">
                    <td><label class="timo-checkbox"><input class="selected_stu" type="checkbox" th:value="${item.id}">
                        <i class="layui-icon layui-icon-ok"></i></label></td>
                    <td th:text="${item.username}">账号</td>
                    <td th:text="${item.nickname}">姓名</td>
                    <td th:text="${#dicts.keyValue('USER_SEX', item.sex)}">性别</td>
                    <td th:text="${item.phone}">电话</td>
                    <td th:text="${item.email}">邮箱</td>
                    <td>
                        <a class="open-popup" data-title="详细信息" th:attr="data-url=@{'/system/user/detail/'+${item.id}}"
                           shiro:hasPermission="system:user:detail"
                           data-size="800,600" href="#">详细</a>
                    </td>
                </tr>
                <button th:if="${!list.isEmpty()}" class="layui-btn open-popup" style="margin-left: 10px;margin-top: 20px;"  th:attr="onclick=@{'addStudentToSubject('+${subjectid}+')'}"> 添加选中的学生</button>
                <tr th:if="${list.isEmpty()}">
                    <td style="text-align: center" colspan="3">暂无可添加学生</td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
<script th:replace="/common/template :: script"></script>
<script type="text/javascript" th:src="@{/js/plugins/jquery-2.2.4.min.js}"></script>
<script type="application/javascript">
    function addStudentToSubject(id) {
        var stus=$(".selected_stu");
        console.log(stus)
        var selected_stu=new Array();
        for(var i=0;i<stus.length;i++){
            if(stus[i].checked){
                selected_stu.push(stus[i].value);
            }
        }
        $.ajax({
            url:"/system/class/realaddstu",
            method:"POST",
            //data:{"data":"hhh","id":id},
            data:{"data":selected_stu,"id":id},
            success:function (data) {
                alert("添加成功");
            },
            error: function (errorinfo) {
                alert("添加失败");
            },

        });
        console.log(selected_stu)

    }
</script>
</body>
</html>